#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <QWidget>
#include <QSerialPort>
#include <QSerialPortInfo>

#define BYTE0(dwTemp)       ( *( (char *)(&dwTemp)    ) )
#define BYTE1(dwTemp)       ( *( (char *)(&dwTemp) + 1) )
#define BYTE2(dwTemp)       ( *( (char *)(&dwTemp) + 2) )
#define BYTE3(dwTemp)       ( *( (char *)(&dwTemp) + 3) )

#define PULSE_TARGET        0x01
#define POSTURE_TARGET      0x02
#define PULSE_RESET         0x04
#define REQ_ADC             0x08
#define MAX_SPEED           0x10
#define MAX_ACC             0x20
#define REQUIRE             0x80

typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef short int s16;

class Protocol :public QSerialPort
{
	u8 Fcn;
	u8 ValidData[12];
public:
	u8 Data_Receive_Precess(u8 RxData);
    u8 Send_u8_Data(u8 data, u8 fcn);
    u8 Send_u8_Data(char* data, u8 fcn, u8 len);
	u8 Send_s16_Data(s16* data, u8 fcn, u8 len);
    u8 RcvdFcn() { return Fcn; };
	void RcvdData(u8* data) { for (int i = 0; i < 12; ++i)data[i] = ValidData[i]; };
    Protocol(QWidget* parent = nullptr) {};
	~Protocol() {};
};

#endif // PROTOCOL_H
